package com.xiangwei.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class getDate {

	/**
	 * 格式化当前日期：yyyy-MM-dd HH:mm:ss
	 * @return Date
	 */
	public static Date getNowdate(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = null;
		try {
			 date = format.parse(format.format(new Date()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
	public static String getStringNowdate(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return format.format(new Date());
	}
	
	/**
	 * 格式化当前日期：yyyy-MM-dd
	 * @return Date
	 */
	public static Date getdate(Date date){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			 date = format.parse(format.format(date));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
	/**
	 * 格式日期：yyyy-MM-dd
	 * @param str
	 * @return
	 */
	public static Date getShortDate(String str){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			 date = format.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	
	/**
	 * 格式日期：yyyyMMdd
	 * @param str
	 * @return
	 */
	public static String getStringDate(){
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		String str = null;
		str = format.format(new Date());
		return str;
	}
	
	/**
	 * 格式日期：yyyyMMddHHmmss
	 * @param str
	 * @return
	 */
	public static String getStringFullDate(){
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		String str = null;
		str = format.format(new Date());
		return str;
	}
	
	public static void main(String[] args) throws ParseException{
		System.out.println(getNowdate().toString());
//		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		  Date d =new Date();
//		  String dd =format.format(d);
//		  Date ddd =format.parse(dd);
//		  System.out.println("dd>>>>  "+dd);
//		  System.out.println("ddd>>>  "+format.format(ddd));
	}
}
